﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BLToolkit.Data;
using BLToolkit.Data.DataProvider;
using System.Data;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
using nwrole.toolbox.sync.extensions;
using nwrole.toolbox.sync;

namespace sync_test
{
  /*  public class TableToDisk : GhostTableSync
    {

        public void run()
        {
            //string columns3 = "VertexId,Efternamn,Fornamn,Mobilnummer,Personnummer,TelefonBostad,TelefonDagtid,Email";
                           // Typ = typ, Status = 0,

            string columns = @"Id,Kök,BalkongEllerUteplats,Hiss,ExtraUtrymme,AntalRum,
                            VäderstreckBalkong,Bredband,KabelTV,SeparatToalett,Hustyp,GemensamYta,
                            SärskiltBoende,Badkar,Dusch, Tomdat, Fromdat,Inredningsar,Lgnnr,Objektnummer,Typ,Ombyggnadsar,Vaning, UppgangId, Adress,
                            Beskrivning,Boendeyta,OmradeId,OmradeStr,{Hyra}
                            ";

            //string columns2 = @"Id";

            saveToDisk(columns.Replace("{Hyra}", "Hyra"), "UthyrningsObjekt", "UthyrningsObjekt.txt");
            saveToDisk(columns.Replace("{Hyra}", "Hyra2"), "UthyrningsObjekt_Test", "UthyrningsObjekt_Test.txt");

            saveToDisk(columns, "Kontohavare", "Kontohavare.txt");
            saveToDisk(columns, "Kontohavare_Test", "Kontohavare_Test.txt");
        }

        public void writeColumn(string s)
        {
        }

        public void saveToDisk(string columns, string table, string fileName)
        {
            DbManager.DefaultConfiguration = ""; //to reset possible previous changes            
            using (DbManager db = new DbManager(destinationDataProvider, DestinationConnectionString))
            {

                string selectSql = sqlBuilder.SelectAll(columns, table);

                db.SetCommand(selectSql);
                IDataReader reader = db.ExecuteReader();

                using (TextWriter writer = File.CreateText(fileName))
                {
                    writer.WriteLine(columns.Replace("\t", "").Replace(",", "\t").Replace("\r", "").Replace("\n", "").Replace(" ", ""));
                    while (reader.Read())
                    {
                        writer.WriteLine("");
                        for (int t = 0; t < reader.FieldCount; t++)
                        {
                            object o = reader[t];
                            if (o == null)
                            {
                                writer.Write("null");
                            }
                            else
                            {
                                writer.Write(o.ToString());
                            }
                            writer.Write("\t");
                        }
                    }
                }
            }
        }
    } */
}

